<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Sitepage
 * @copyright  Copyright 2010-2011 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: index.tpl 2011-05-05 9:40:21Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */
?>

<?php 
	include APPLICATION_PATH . '/application/modules/Sitepage/views/scripts/Adintegration.tpl';
?>

<?php
  $this->headLink()
  	->prependStylesheet($this->seaddonsBaseUrl().'/application/modules/Sitepage/externals/styles/sitepage-tooltip.css');
  $currency = Engine_Api::_()->getApi('settings', 'core')->getSetting('payment.currency', 'USD');
?>

<script type="text/javascript">
   var page_communityads;
	    var contentinformtion;
      var page_showtitle;
  if(contentinformtion == 0) {
		if($('global_content').getElement('.layout_activity_feed')) {
			$('global_content').getElement('.layout_activity_feed').style.display = 'none';
		}		
		if($('global_content').getElement('.layout_core_profile_links')) {
			$('global_content').getElement('.layout_core_profile_links').style.display = 'none';
		}
		if($('global_content').getElement('.layout_sitepage_info_sitepage')) {
			$('global_content').getElement('.layout_sitepage_info_sitepage').style.display = 'none';
		}	
		
		if($('global_content').getElement('.layout_sitepage_location_sitepage')) {
			$('global_content').getElement('.layout_sitepage_location_sitepage').style.display = 'none';
		}	
  }
</script>

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

<?php $sitepage = $this->sitepage; ?>
<script type="text/javascript">
  var myLatlng;
  function initialize() {
    var myLatlng = new google.maps.LatLng(<?php echo $this->location->latitude; ?>,<?php echo $this->location->longitude; ?>);
    var myOptions = {
      zoom: <?php echo $this->location->zoom; ?> ,
      center: myLatlng,
    //  navigationControl: true,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }

    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    var contentString = '<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+'<ul class="sitepages_locationdetails"><li>'+
			'<div class="sitepages_locationdetails_info_title">'+
	    	"<?php echo $this->string()->escapeJavascript($sitepage->getTitle())?>"+
        '<div class="fright">'+
          '<span >'+
            <?php if ($sitepage->featured == 1): ?>
	            '<?php echo $this->htmlImage('application/modules/Sitepage/externals/images/sitepage_goldmedal1.gif', '', array('class' => 'icon', 'title' => $this->string()->escapeJavascript($this->translate('Featured')))) ?>'+	            <?php endif; ?>
          '</span>'+
          '<span>'+
            <?php if ($sitepage->sponsored == 1): ?>
	            '<?php echo $this->htmlImage('application/modules/Sitepage/externals/images/sponsored.png', '', array('class' => 'icon', 'title' => $this->string()->escapeJavascript($this->translate('Sponsored')))) ?>'+
          	<?php endif; ?>
          '</span>'+
        '</div>'+
        '<div class="clear"></div>'+
      '</div>'+
      '<div class="sitepages_locationdetails_photo" >'+
    		'<?php echo  $this->itemPhoto($sitepage, 'thumb.normal') ?>'+
	    '</div>'+ 
      '<div class="sitepages_locationdetails_info">'+
				<?php if ($this->ratngShow): ?>
					<?php if (($sitepage->rating > 0)): ?>

						<?php 
							$currentRatingValue = $sitepage->rating;
							$difference = $currentRatingValue- (int)$currentRatingValue;
							if($difference < .5) {
								$finalRatingValue = (int)$currentRatingValue;
							}
							else {
								$finalRatingValue = (int)$currentRatingValue + .5;
							}	
						?>

						'<span class="clear" title="<?php echo $finalRatingValue.$this->translate(' rating'); ?>">'+
							<?php for ($x = 1; $x <= $sitepage->rating; $x++): ?>
								'<span class="rating_star_generic rating_star" ></span>'+
							<?php endfor; ?>
							<?php if ((round($sitepage->rating) - $sitepage->rating) > 0): ?>
								'<span class="rating_star_generic rating_star_half"></span>'+
							<?php endif; ?>
						'</span>'+
					<?php endif; ?>
				<?php endif; ?>

        '<div class="sitepages_locationdetails_info_date">'+
          '<?php echo $this->timestamp(strtotime($sitepage->creation_date)) ?> - <?php echo $this->string()->escapeJavascript($this->translate('posted by')); ?> '+
          '<?php echo $this->htmlLink($sitepage->getOwner()->getHref(), $this->string()->escapeJavascript($sitepage->getOwner()->getTitle())) ?>'+
        '</div>'+

        '<div class="sitepages_locationdetails_info_date">'+
	      	'<?php echo $this->string()->escapeJavascript($this->translate(array('%s comment', '%s comments', $sitepage->comment_count), $this->locale()->toNumber($sitepage->comment_count))) ?>,&nbsp;'+
	        '<?php echo $this->string()->escapeJavascript($this->translate(array('%s view', '%s views', $sitepage->view_count), $this->locale()->toNumber($sitepage->view_count))) ?>'+
		    '</div>'+
        <?php if($sitepage->price && $this->enablePrice): ?>
                '<div class="sitepages_locationdetails_info_date">'+
								"<i><b>"+"<?php echo  $this->locale()->toCurrency($sitepage->price, $currency) ?>"+ "</b></i>"+
							'</div>'+
        <?php endif; ?>
			'<div class="sitepages_locationdetails_info_date">'+
				"<i><b>"+"<?php echo $this->string()->escapeJavascript( $this->location->location); ?>"+ "</b></i>"+
	      '</div>'+
        
 		  '</div>'+
 		  '<div class="clear"></div>'+
	 ' </li></ul>'+


      '</div>';
   
    var infowindow = new google.maps.InfoWindow({
      content: contentString ,
      size: new google.maps.Size(250,50)

    });

    var marker = new google.maps.Marker({
      position: myLatlng,
      map: map,
      title: "<?php echo str_replace('"', ' ',$sitepage->getTitle())?>"
    });
    google.maps.event.addListener(marker, 'click', function() {
       
      infowindow.open(map,marker);
    });

    <?php if(!empty($this->showtoptitle)):?>
      $$('.tab_<?php echo $this->identity_temp; ?>').addEvent('click', function() {
      google.maps.event.trigger(map, 'resize');
      map.setZoom(<?php echo $this->location->zoom; ?> );
      map.setCenter(myLatlng);
    });
    <?php else:?>
      $$('.tab_layout_sitepage_location_sitepage').addEvent('click', function() {
      google.maps.event.trigger(map, 'resize');
      map.setZoom(<?php echo $this->location->zoom; ?> );
      map.setCenter(myLatlng);
    });
    <?php endif;?>

    google.maps.event.addListener(map, 'click', function() {
      
      infowindow.close();
			google.maps.event.trigger(map, 'resize');
      map.setZoom(<?php echo $this->location->zoom; ?> );
      map.setCenter(myLatlng);
    });
  }
</script>

<div id='id_<?php echo $this->content_id; ?>'>
  <?php if($this->showtoptitle == 1):?>
		<div class="layout_simple_head" id="layout_map">
			<?php echo $this->translate($this->sitepage->getTitle(). "'s Map");?>
		</div>
	<?php endif;?>

	<?php if(Engine_Api::_()->getDbtable('modules', 'core')->isModuleEnabled('communityad') && Engine_Api::_()->getApi('settings', 'core')->getSetting('sitepage.communityads', 1) && Engine_Api::_()->getApi('settings', 'core')->getSetting('sitepage.adlocationwidget', 3) && $page_communityad_integration && Engine_Api::_()->sitepage()->showAdWithPackage($this->sitepage)):?>
			<div class="layout_right" id="communityad_location">
				<?php
				  echo $this->content()->renderWidget("sitepage.page-ads", array('limit' => Engine_Api::_()->getApi('settings', 'core')->getSetting('sitepage.adlocationwidget', 3), 'tab' =>'location', 'communityadid' => 'communityad_location', 'isajax' => 0)); 
				?>
			</div>
	
		<div class="layout_middle">
	<?php endif;?>
			<div class='profile_fields'>
			  <ul class="sitepage_profile_location">
			    <li>
			  		<div id="map_canvas"></div>
			    </li>
			  </ul>
			  <h4>
			    <span><?php echo $this->translate('Location Information') ?></span>
			  </h4>
			  <ul>
			    <li>
		        <span><?php echo $this->translate('Location:'); ?> </span>
		        <span><b><?php echo  $this->location->location; ?> </b></span>
			    </li>
			    <?php if(!empty($this->location->formatted_address)):?>
				    <li>
				      <span><?php echo $this->translate('Formatted Address:'); ?> </span>
				      <span><?php echo $this->location->formatted_address; ?> </span>
				    </li>
			    <?php endif; ?>
			    <?php if(!empty($this->location->address)):?>
				    <li>
				      <span><?php echo $this->translate('Street Address:'); ?> </span>
				      <span><?php echo $this->location->address; ?> </span>
				    </li>
			    <?php endif; ?>
			    <?php if(!empty($this->location->city)):?>
				    <li>
				      <span><?php echo $this->translate('City:'); ?></span>
				      <span><?php echo $this->location->city; ?> </span>
				    </li>
			    <?php endif; ?>
			    <?php if(!empty($this->location->zipcode)):?>
				    <li>
				      <span><?php echo $this->translate('Zipcode:'); ?></span>
				      <span><?php echo $this->location->zipcode; ?> </span>
				    </li>
			    <?php endif; ?>
			    <?php if(!empty($this->location->state)):?>
				    <li>
				      <span><?php echo $this->translate('State:'); ?></span>
				      <span><?php echo $this->location->state; ?></span>
				    </li>
			    <?php endif; ?>
			    <?php if(!empty($this->location->country)):?>
						<li>
						  <span><?php echo $this->translate('Country:'); ?></span>
						  <span><?php echo $this->location->country; ?></span>
						</li>
			    <?php endif; ?>
			  </ul>
			</div>
	<?php if(Engine_Api::_()->getDbtable('modules', 'core')->isModuleEnabled('communityad') && Engine_Api::_()->getApi('settings', 'core')->getSetting('sitepage.communityads', 1) && Engine_Api::_()->getApi('settings', 'core')->getSetting('sitepage.adlocationwidget', 3)  && $page_communityad_integration && Engine_Api::_()->sitepage()->showAdWithPackage($this->sitepage)):?>
		</div>
	<?php endif; ?>
</div>

<style type="text/css">
  #map_canvas {
    width: 100%;
    height: 500px;
  
  }
  #map_canvas > div{
    height: 500px;
  }
  #infoPanel {
    float: left;
    margin-left: 10px;
  }
  #infoPanel div {
    margin-bottom: 5px;
  }
</style>

<script type="text/javascript">
  window.addEvent('domready',function(){
    initialize();
  });
  var page_communityad_integration = '<?php echo $page_communityad_integration; ?>';
  var adwithoutpackage = '<?php echo Engine_Api::_()->sitepage()->showAdWithPackage($this->sitepage) ?>';
	var location_ads_display = '<?php echo Engine_Api::_()->getApi('settings', 'core')->getSetting('sitepage.adlocationwidget', 3);?>';
	$$('.tab_<?php echo $this->identity_temp; ?>').addEvent('click', function() 
	{ 	
		if(page_showtitle != 0) {
			if($('profile_status')) {
				$('profile_status').innerHTML = "<h2><?php echo $this->string()->escapeJavascript($this->sitepage->getTitle())?><?php echo $this->translate(' &raquo; ');?><?php echo $this->translate('Map');?></h2>";	
			}
			if($('layout_map')) {
				$('layout_map').style.display = 'block';
			}	    	
		}
    hideWidgetsForModule('sitepagelocation');
		$('id_' + <?php echo $this->content_id ?>).style.display = "block";
		if ($('id_' + prev_tab_id) != null && prev_tab_id != 0 && prev_tab_id != '<?php echo $this->content_id; ?>') {
			$('global_content').getElement('.'+ prev_tab_class).style.display = 'none';
		}
		prev_tab_id = '<?php echo $this->content_id; ?>';	
		prev_tab_class = 'layout_sitepage_location_sitepage';

		if(page_showtitle == 1 && page_communityads == 1 && location_ads_display != 0 && page_communityad_integration != 0 && adwithoutpackage != 0) {
			if ($$('.layout_left')){
				$$('.layout_left').setStyle('display', 'block');
				if($('thumb_icon')) {
					$('thumb_icon').style.display = 'none';
				}
			}	    	
		} else if(page_showtitle == 0 && page_communityads == 1 && location_ads_display != 0 && page_communityad_integration != 0 && adwithoutpackage != 0) {
			if ($$('.layout_left')){
				$$('.layout_left').setStyle('display', 'none');
				if($('thumb_icon')) {
					$('thumb_icon').style.display = 'block';
				}
			}		    	
			
		}
		
		if(page_communityads == 1 && location_ads_display == 0) {
			if ($$('.layout_left')){
				$$('.layout_left').setStyle('display', 'block');
				if($('thumb_icon')) {
					$('thumb_icon').style.display = 'none';
				}
			}    	
		}
	});
</script>